package au.com.handsunited.model.validators.entity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import au.com.handsunited.model.User;
import au.com.handsunited.model.User;
import au.com.handsunited.model.validators.address.UserLocationValidator;
import au.com.handsunited.model.validators.availability.AvailabilityValidator;
import au.com.handsunited.model.validators.contactinfo.UserContactInfoValidator;

/**
 * @author Arun Chandrasekhar
 * @date 05/01/2007 10:23:21 AM
 */
public class UserValidator extends BaseEntityValidator {


	private static Logger logger = LoggerFactory.getLogger(UserValidator.class);

	/**
	 *
	 */
	public UserValidator(UserLocationValidator locationValidator, UserContactInfoValidator contactInfoValidator, AvailabilityValidator availabilityValidator) {

		super(locationValidator, contactInfoValidator, availabilityValidator);
	}

	/**
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	@Override
	public boolean supports(Class clazz) {
		return clazz.isAssignableFrom(User.class);
	}

	/**
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */
	@Override
	public void validate(Object target, Errors errors) {

		super.validate(target, errors);

		User user = (User) target;
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required", "First name is required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required", "Last name is required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "username.required", "User Name is required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required", "Password is required");
	}

}
